<template>
	<view class="page">
    <u-navbar :fixed="false" leftIconColor="#000" titleStyle="color: #000 !important;" title="Gowork" placeholder bgColor="transparent"></u-navbar>
    <image class="logo" src="https://gowork365.com/prod-api/profile/mini/logo.png" mode="widthFix" />
    <button class="getPhoneNumber" :phone-number-no-quota-toast="false" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">手机号快捷登录</button>
	</view>
</template>

<script>
import { login } from '@/api/index'

export default {
  data() {
    return {
    }
  },
  onLoad() {

  },
  methods: {
    getPhoneNumber (e) {
      const that = this
			if(e.detail.errMsg == 'getPhoneNumber:fail user deny') {
      } else if(e.detail.code) {
        uni.login({
          provider: 'weixin', //使用微信登录
          success: async function(loginRes) {
            uni.showLoading({ mask: true })
            login({ jsCode: loginRes.code, phoneCode: e.detail.code }).then(res => {
              uni.hideLoading({})
              if(res.code == 230) {
                uni.showModal({
                  title: '您还不是平台用户',
                  content: '检测到您的手机号码尚未开通平台相关服务，现在注册可免费试用'+res.msg+'天',
                  confirmText: '立即注册',
                  success: function (res) {
                    if (res.confirm) {
                      that.jumpTo('/pages/login/register')
                    }
                  }
                });
              } else if(res.token) {
                uni.setStorageSync('token', res.token)
                uni.setStorageSync('userInfo', res.user)
                uni.setStorageSync('permissions', res.permissions)
                uni.setStorageSync('enterpriseInfo', res.enterpriseInfo || {})
                that.reLaunch('/pages/index/index')
              }
            })
          }
        });
      }
    },
  }
}
</script>

<style lang="less" scoped>
.page {
  width: 100%;
  min-height: 100vh;
  background: #FFF;
  position: relative;
  .logo {
    width: 228rpx;
    height: auto;
    display: block;
    margin: 156rpx auto 424rpx;
  }
  .getPhoneNumber {
    width: 654rpx;
    height: 96rpx;
    line-height: 96rpx;
    background: #00BA81;
    border-radius: 4rpx;
    margin: 0 auto;
    font-family: PingFangSC, PingFang SC;
    font-size: 32rpx;
    color: #FFFFFF;
    text-align: center;
  }
}
</style>
